/* This file is part of GSMC.
 * 
 * GSMC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GSMC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GSMC.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.hpxn.gsmc.action;

import java.util.HashMap;
import java.util.Iterator;

import org.apache.log4j.Logger;

/**
 * Use this class to test if your game event mappings are correct.
 * 
 * @author peterdi
 * 
 */
public class RawAction extends BaseAction {

	private Logger log;

	public RawAction() {
		log = Logger.getLogger( getClass().getCanonicalName() );
	}

	@Override
	public void run() {

		HashMap<String, String> playerMap = getEvent().getPlayerMap();
		HashMap<String, String> paramMap = getEvent().getParameterMap();
		
		log.info( "--- START RAW EVENT ---" );
		log.info( getEvent().getRawEvent() );
		

		if ( playerMap != null && !playerMap.isEmpty() ) {
			StringBuilder wString = new StringBuilder();

			for ( Iterator<String> wIt = playerMap.keySet().iterator(); wIt
					.hasNext(); ) {
				String wKey = wIt.next();
				wString.append( wKey + ": " + playerMap.get( wKey ) + " " );
			}

			log.debug( "[" + getEvent().getServer().getName() + "] [" + getMappingKey()
					+ "] " + wString.toString() );
		}

		if ( paramMap != null && !paramMap.isEmpty() ) {
			StringBuilder wString = new StringBuilder();

			for ( Iterator<String> wIt = paramMap.keySet().iterator(); wIt
					.hasNext(); ) {
				String wKey = wIt.next();
				wString.append( wKey + ": " + paramMap.get( wKey ) + " " );
			}

			log.debug( "[" + getEvent().getServer().getName() + "] [" + getMappingKey()
					+ "] " + wString.toString() );
		}
		log.info( "--- END RAW EVENT ---" );
	}
}
